<template>
  <div>
    <el-row style="margin-bottom: 20px">
      <el-col :span="24">
        <el-button type="warning" plain @click="keepMoBan"
          >该分配保存模板</el-button
        >
        <el-button type="warning" plain @click="diaoyong"
          >调用上一个模板</el-button
        >
        <div style="float: right">
          <!-- <el-button type="primary" plain @click="importjjBtn()"
            >奖金导入</el-button
          > -->
          <el-button type="primary" v-if="rowProcessStatus==3" plain @click="checkApproval"
            >查看领导审批意见</el-button>
          <el-button type="primary" plain @click="fnchaifen"
            >奖金分配</el-button
          >
          <!-- <el-button type="primary" plain @click="addOrUpdateHandle"
            >总额修改</el-button
          > -->
          <el-button type="primary" plain @click="directionalBtn"
            >定向分配</el-button
          >
          <el-button type="primary" plain @click="monifp(true)">分配计算</el-button>
          <el-button type="primary" plain @click="downloadtemp"
            >下载模板</el-button
          >
          <el-upload
            class="upload-demo"
            action="/admin/sys-file/upload"
            accept=".xls,.xlsx"
            :headers="headers"
            :before-upload="beforeFileUpload"
            :on-change="handleChange"
            :on-success="handleUploadSuccess"
            :show-file-list="false"
            :file-list="fileList"
            style="display: inline; margin-left: 10px; margin-right: 10px"
          >
            <el-button size="small" type="primary">导入分组</el-button>
          </el-upload>
          <el-button type="primary" :disabled="tableDataChild.length==0" plain @click="onExport">导出</el-button>
          <el-button
            type="primary"
            plain
            v-if="
              permissions.jiangjin_jiangjinfpjjfpdjb_add &&
              row.bmJj > 0 &&
              row.fpZt == '分配中'
            "
            @click="tsJjfp('fpts')"
            >提交审核</el-button
          >
          <el-upload
            class="upload-demo"
            :action="jjUrl"
            accept=".xls,.xlsx"
            :headers="headers"
            :on-success="handleUploadSuccessJj"
            :show-file-list="false"
            style="display: inline; margin-left: 10px; margin-right: 10px"
          >
            <el-button size="small" type="primary">导入奖金结果</el-button>
          </el-upload>
          <!--                <el-button type="primary" plain @click="fanhui">返回</el-button>-->
        </div>
      </el-col>
    </el-row>
    <div class="boxsty zhiBiao popover-style-parent-div">
      <el-col :span="24">
        <el-form :model="form">
          <el-col
            :span="5"
            :style="{ height: colHeightThree, overflow: 'hidden' }"
          >
            <div>
              <el-form-item label="人员分组:" :key="2">
                <el-checkbox-group v-model="form.check" @change="changeVal">
                  <el-checkbox
                    v-for="item in checkList"
                    :key="item.id"
                    :label="item.id"
                    >{{ item.ryfzMc }}</el-checkbox
                  >
                </el-checkbox-group>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="4">
            <el-popover
              placement="bottom-end"
              title="人员分组"
              width="900"
              trigger="hover"
              v-model="visiblePopover1"
            >
              <el-form-item :key="21">
                <el-checkbox-group v-model="form.check">
                  <el-checkbox
                    v-for="item in checkList"
                    :key="item.id"
                    :label="item.id"
                    >{{ item.ryfzMc }}</el-checkbox
                  >
                </el-checkbox-group>
              </el-form-item>
              <el-button
                slot="reference"
                type="text"
                @click="visiblePopover1 = !visiblePopover1"
                >更多<i
                  :class="
                    visiblePopover1
                      ? 'el-icon-arrow-down'
                      : 'el-icon-arrow-right'
                  "
                ></i
              ></el-button>
            </el-popover>
            <!--                                    <el-button type="text" @click="moreOne(1)">更多<i :class="colHeightshow?'el-icon-arrow-down':'el-icon-arrow-right'"></i></el-button>-->
            <el-button type="primary" plain @click="add_jigougrouping($event)"
              >确认添加</el-button
            >
            <el-button type="primary" plain @click="addOtherPerson"
              >修改分组</el-button
            >
          </el-col>
        </el-form>
      </el-col>
    </div>
    <el-row>
      <el-col :span="24">
        <!-- :span-method="objectSpanMethod" -->
        <el-col :span="8">
          <el-button
            type="primary"
            v-if="allVisoble"
            @click="bacthGong"
            style="margin-top: 20px"
            >批量修改公式</el-button
          >
          <el-table
            :data="tableData"
            ref="multipleTable"
            :span-method="objectSpanMethod"
            border
            max-height="350"
            @selection-change="selectionChange"
            style="width: 100%; margin-top: 10px"
          >
            <el-table-column type="selection" width="50"> </el-table-column>
            <el-table-column prop="jjxMc" min-width="110" label="奖项">
              <template slot="header" slot-scope="scope">
                <el-select
                  v-model="jiangxiang"
                  @change="chaixuanJj(jiangxiang)"
                  clearable
                  placeholder="奖项"
                >
                  <el-option
                    v-for="it in jiangJList"
                    :key="it.jjxId"
                    :label="it.jjxMc"
                    :value="it.jjxId"
                  >
                  </el-option>
                </el-select>
              </template>
              <template slot-scope="scope">
                <span style="cursor: pointer"
                  >{{ scope.row.jjxMc }}({{ scope.row.jjJe }})</span
                >
                <el-button
                  v-if="!scope.row.flag"
                  type="text"
                  @click="jjzjFromOpen(scope.row.id)"
                  >追加</el-button
                >
              </template>
            </el-table-column>
            <el-table-column prop="jgFzName">
              <template slot="header" slot-scope="scope">
                <el-select
                  v-model="name"
                  clearable
                  @change="shaixuanR(name)"
                  placeholder="人员分组"
                >
                  <el-option
                    v-for="item in checkList"
                    :key="item.id"
                    :label="item.ryfzMc"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </template>
              <template slot-scope="scope">
                <span>{{
                  scope.row.fzName
                }}</span>

              </template>
            </el-table-column>
            <el-table-column prop="xsJe" width="100" label="输入金额">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.xsJe"
                  type="number"
                  :disabled="scope.row.thisId == null"
                  @blur="changeJe(scope.row)"
                  placeholder=""
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column align="center" width="150" label="操作">
              <template slot-scope="scope">
                <el-button
                v-if="scope.row.fzName"
                  type="warning"
                  plain
                  size="mini"
                  @click="xuanGs(scope.row)"
                  >公式</el-button
                >
                <el-button
                  type="danger"
                  v-if="scope.row.thisId != null"
                  plain
                  size="mini"
                  @click="renSplice(scope.row)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <el-col :span="24" style="margin-top: 20px">
            <el-form :model="row">
              <el-col :span="18">
                <el-form-item label="请于" style="width:400px;">
                  <el-date-picker
                    v-model="row.jjReportTime"
                    type="date"
                    format="yyyy-MM-dd"
                    style="width: 160px"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期"
                    @change="onupdateReportTime"
                  >
                  </el-date-picker>
                  完成奖金上报工作
                </el-form-item>
              </el-col>
              <!-- <el-col :span="10">
                            <el-form-item label="具体工作要求">
                                <el-upload
                                    class="upload-demo"
                                    action=""
                                    :on-success="handleSuccess">
                                    <el-button size="small" type="primary">上传附件</el-button>
                                </el-upload>
                            </el-form-item>
                        </el-col> -->
            </el-form>
          </el-col>
        </el-col>
        <el-col :span="15" style="float: right">
          <!--模拟分配-->
          <renyuanResults
            v-if="showMo"
            ref="renyuanResults"
            @renyuanChild="renyuanChild"
          ></renyuanResults>
          <div class="text-center">
            <el-button type="primary" size="big" plain @click="fanhui"
              >返回</el-button
            >
          </div>
        </el-col>
      </el-col>
    </el-row>
    <!--添加机构-->
    <jigoutableForm
      ref="jigoutableRef"
      @refreshDataList="refreshDataList"
    ></jigoutableForm>
    <!--选择公式-->
    <gongshiCard ref="gongshi"></gongshiCard>
    <!--调用模板-->
    <mubanTable
      ref="mubanTableRef"
      @mubanTableChild="mubanTableChild"
    ></mubanTable>
    <!--奖金项拆分-->
    <chaifenCard ref="chaifen" @chaifenChild="chaifenChild"></chaifenCard>
    <!--追加奖金-->
    <jjzjFrom ref="jjzjFrom" @chaifenChild="chaifenChild"></jjzjFrom>
    <!--批量修改公式-->
    <batchGongshi
      ref="batchGongshi"
      @chaifenChild="chaifenChild"
    ></batchGongshi>
    <!--放大模拟测试-->
    <el-dialog
      title="分配计算"
      :visible.sync="mninnerVisible"
      append-to-body
      :fullscreen="true"
    >
      <renyuanResults ref="renyuanResults"></renyuanResults>
    </el-dialog>
    <el-dialog
      title="定向分配"
      :visible.sync="dxfpinnerVisible"
      append-to-body
      :fullscreen="true"
    >
      <jiangjinfpjjfpdjbFpDxfp
        ref="jiangjinfpjjfpdjbFpDxfp"
        @refreshDataList="callback"
      ></jiangjinfpjjfpdjbFpDxfp>
    </el-dialog>
    <table-form
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="getDataList"
    ></table-form>
    <jjimportDiaolg :importjjDiaolgData="importjjDiaolgData"></jjimportDiaolg>
    <!-- 提审选人 -->
    <personCard ref="usercomment" :isJjfp="true" @submitfy="submitfy"></personCard>
    <!-- 外部人员 -->
    <per-selection v-if="perSelectionVisible" ref="perselection"></per-selection>
    <!--查看领导审批意见-->
    <checkLeaders ref="checkLeaders"></checkLeaders>
  </div>
</template>

<script>
import jigoutableForm from "@/views/jiangjin/jiangjinjjjgfz/jiangjinjjjgfz-form";
import gongshiCard from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/gongshiCard";
import renyuanResults from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/renyuanResults";
import chaifenCard from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/chaifen";
import perSelection from '@/views/jiangjin/jiangjinryfzb/personnelSelection'
import {
  getRyfzbList,
  useTemplate,
  saveTemplate,
} from "@/api/jiangjin/jiangjinryfzb";
import jiangjinfpjjfpdjbFpDxfp from "../jiangjinfpjjfpdjb-fp-dxfp";
import {
  getListCf,
  saveFZ,
  jiangjinmxcffz,
  saveJe,
  downloadTemplate,
  downloadRyfpp,
  updateReportTime
} from "@/api/jiangjin/jiangjinjjxxxb";
import mubanTable from "@/views/jiangjin/jiangjinfpjjfpdjb/muban-table";
import jjimportDiaolg from "../importjjDiaolg";
import TableForm from "../jiangjinfpjjfpdjb-form";
import jjzjFrom from "../jiangjinfpjjfpdjb-jjly-form";
import batchGongshi from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/batchGongshi";
import store from "@/store";
import request from "@/router/axios";
import { mapGetters } from "vuex";
//import UserCommonSelect from "@/views/hetongrenwu/components/usercomment-select";
import { sendFP } from "@/api/jiangjin/jiangjinfpjjfpdjb";
import personCard from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/personCard";
import checkLeaders from "@/views/jiangjin/jiangjinfpjjfpdjb/xincaozuo/checkLeaders";
import { getStore, setStore } from "@/util/store";
export default {
  components: {
    jigoutableForm,
    gongshiCard,
    renyuanResults,
    chaifenCard,
    jiangjinfpjjfpdjbFpDxfp,
    mubanTable,
    TableForm,
    jjzjFrom,
    batchGongshi,
    jjimportDiaolg,
   // UserCommonSelect,
    perSelection,
    personCard,
    checkLeaders
  },
  data() {
    return {
      form: {
        check: [],
      },
      checkList: [],
      visiblePopover1: false,
      colHeightThree: "40px",
      jjDeptId: "",
      jjxList: [],
      tableData: [{ jjxMc: "优秀员工奖", je: "2200", jgFzName: "B组" }],
      jiangxiang: "",
      name: "",
      spanArr: [],
      dataForm: {},
      gqTime: "",
      innerVisible: true,
      isFullscreen: false,
      showMo: false,
      rowId: "",
      dxfpinnerVisible: false,
      row: {},
      tableDataOld: [],
      jiangJList: [],

      mninnerVisible: false,
      addOrUpdateVisible: false,
      fileList: [],
      headers: {
        'TENANT-ID': getStore({ name: "tenantId" })
        ? getStore({ name: "tenantId" })
        : "1",
        Authorization: "Bearer " + store.getters.access_token,
      },
      allVisoble: false,
      rowList: [],
      importjjDiaolgData: {},
      autoShowJJFP: true, //自动显示奖金分配
      rowPid:"",
      perSelectionVisible:false,
      zongE:0,
      rowProcessStatus:0,
      tableDataChild:[],
      tableColumnChild:[],
      jjUrl:""
    };
  },
  computed: {
    ...mapGetters(["permissions"]),
  },
  methods: {
    //改变上报日期
    onupdateReportTime(){
      var params={
        fpId:this.row.id,
        jjReportTime:this.row.jjReportTime
      }
      updateReportTime(params).then(res=>{
        if(res.data.code==0){
          this.$message.closeAll();
          this.$message.success('操作成功!')
        }
      })
    },
    //导出
    onExport(){

      var params={
        tableData:this.tableDataChild,
        tableColumn:this.tableColumnChild
      }
      downloadRyfpp(params).then(res=>{
        this.$message.closeAll();
        this.$message.success("导出成功!");
        let url = window.URL.createObjectURL(new Blob([res.data]));
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", "人员奖金分配导出.xls");
        document.body.appendChild(link);
        link.click();
      })
    },
    //领导审批意见
    checkApproval(){
      this.$nextTick(()=>{
        this.$refs.checkLeaders.init(this.row.processIdFf)
      })
    },
    //分配提审
    tsJjfp(type) {
      this.fpId = this.row.id;
      this.tstype = type;
      this.$nextTick(() => {
        this.$refs.usercomment.init("12", "allTree", "", "htcj",'提交审核');
      });
    },
    submitfy(data) {
      var ids = "";
      data.tableDataUser.forEach((ele) => {
        ids = ids + ele.userId + ",";
      });
      var params = {
        fpId: this.fpId,
        userList: ids,
        pd:data.formRen.isFs,
        asssj:data.formRen.userId,
      };
      if (this.tstype == "fpts") {
        sendFP(params).then((res) => {
          this.$message.closeAll()
          this.$message.success("提交审核成功");
          this.fanhui();
        });
      } else {
        sendFF(params).then((res) => {
          this.$message.closeAll()
          this.$message.success("发放提审成功");
          this.fanhui();
        });
      }
      // data.tableDataUser;
    },
    selectionChange() {
      var rows = this.$refs.multipleTable.selection;
      var count = 0;
      if (rows.length < 1) {
        this.allVisoble = false;
        return;
      }
      rows.forEach(function (item, index) {
        if (item.fzId == null) {
          count++;
        }
      });

      if (count > 0) {
        this.allVisoble = false;
      } else {
        this.allVisoble = true;
      }
      this.rowList = [];
      this.tableData.forEach((item) => {
        rows.forEach((it) => {
          if (item.id == it.id) {
            this.rowList.push(item);
          }
        });
      });
    },
    //增加外部人员
    addOtherPerson() {
      if(this.form.check.length==0){
        this.$message.closeAll()
        this.$message.warning('请选择要修改的分组!')
        return false
      }
      if(this.form.check.length>1){
        this.$message.closeAll()
        this.$message.warning('只能选择一条分组进行修改!')
        return false
      }
      if(this.form.check.length==1){
        this.checkList.forEach(item=>{
          if(item.id==this.form.check[0]){
            this.perSelectionVisible = true;
              this.$nextTick(() => {
              this.$refs.perselection.init({jjDeptId: item.jjDeptId, id: item.id});
            });
          }
        })
      }

    },
    //批量修改公式
    bacthGong() {
      this.$nextTick(() => {
        this.$refs.batchGongshi.init(this.rowList, "geren");
      });
    },
    init(row) {
      this.row = row;
      this.jjDeptId = row.jjDeptId;
      this.rowId = row.id;
      this.rowPid=row.pid;
      this.jjUrl='/jiangjin/jiangjinfpjjfpdjb/importExcelForFee/'+this.rowId
      this.rowProcessStatus=row.processStatus;
      this.getjigou(this.jjDeptId);
      this.getData();
      /*取消注释了*/
      if (this.rowId) {
        this.monifp(false);
      }
      //  显示奖金分配
      if (this.autoShowJJFP) {
        this.fnchaifen();
      }
    },
    getData() {
      getListCf(this.rowId, "ry").then((res) => {
        this.tableData = res.data.data;
        this.tableDataOld = res.data.data;
        this.getSpanArr(this.tableData);
        this.jiangJList = this.unique(
          JSON.parse(JSON.stringify(res.data.data))
        );
      });
    },
    // 奖金分配
    importjjBtn() {
      this.importjjDiaolgData = {
        visible: true,
        showTab: "renyuan",
        activeName: "renyuan",
      };
    },
    //奖金追加
    jjzjFromOpen(cfid) {
      this.$nextTick(() => {
        this.$refs.jjzjFrom.init(this.rowId, this.jjDeptId, cfid);
      });
    },
    //去重
    unique(arr) {
      for (var i = 0; i < arr.length; i++) {
        for (var j = i + 1; j < arr.length; j++) {
          if (arr[i].id == arr[j].id && arr[i].jjxId == arr[j].jjxId) {
            //第一个等同于第二个，splice方法删除第二个
            arr.splice(j, 1);
            j--;
          }
        }
      }

      return arr;
    },
    //人员分组合并单元格
    getSpanArr(data) {
      function sortData(obj1, obj2) {
        return obj1.id - obj2.id;
      }
      var dataArr = data.sort(sortData);
      this.spanArr = [];
      for (var i = 0; i < dataArr.length; i++) {
        if (i === 0) {
          this.spanArr.push(1);
          this.pos = 0;
        } else {
          // 判断当前元素与上一个元素是否相同
          if (dataArr[i].id === dataArr[i - 1].id) {
            this.spanArr[this.pos] += 1;
            this.spanArr.push(0);
          } else {
            this.spanArr.push(1);
            this.pos = i;
          }
        }
      }
    },
    //筛选人员
    shaixuanR(value) {
      var list = [];
      if (value != "") {
        this.tableDataOld.forEach((item) => {
          if (item.fzId == value) {
            list.push(item);
          }
        });
        this.tableData = list;
      } else {
        this.tableData = this.tableDataOld;
      }
    },
    //筛选奖金
    chaixuanJj(value) {
      console.log(value);
      var list = [];
      if (value != "") {
        this.tableDataOld.forEach((item) => {
          if (item.jjxId == value) {
            list.push(item);
          }
        });
        this.tableData = list;
      } else {
        this.tableData = this.tableDataOld;
      }
    },
    jigouchange() {},
    //拆分子集过来
    chaifenChild() {
      this.autoShowJJFP = false; //关闭自动弹出拆分弹框
      this.getData();
    },
    //奖金项拆分
    fnchaifen() {
      this.$nextTick(() => {
        console.log(this.rowId);
        this.$refs.chaifen.init(this.jjDeptId, this.rowId,this.rowPid, "ry");
      });
    },
    add_jigougrouping() {
      var data = this.$refs.multipleTable.selection;
      if (data.length == 0) {
        this.$message.closeAll()
        this.$message.warning("请选择要分配的奖金项!");
        return false;
      }
      var params = {
        ids: this.form.check.toString(),
        jjxList: JSON.stringify(data),
        cfLx: "ry",
      };
      saveFZ(params).then((res) => {
        this.getData();
        //添加分组时，同步执行【分配计算】
        this.monifp(false);
      });
      // this.$nextTick(() => {
      //     this.$refs.jigoutableRef.init(this.jjDeptId, id);
      // });
    },
    //删除
    renSplice(row) {
      jiangjinmxcffz(row.thisId).then((res) => {
        if (res.data.code == 0) {
          this.$message.closeAll()
          this.$message.success("删除成功!");
          this.getData();
          //删除分组时，同步执行【分配计算】
          this.monifp(false);
        }
      });
    },
    //修改金额
    changeJe(row) {
      saveJe(row).then((res) => {
        if (res.data.code == 0) {

          if (res.data.data == false) {
             this.$message.closeAll()
            this.$message.warning("不允许超额!");
          } else {
             this.$message.closeAll()
            this.$message.success("修改成功!");
          }
          this.getData();
        }
      });
    },
    //模拟分配
    monifp(updateFlag) {
      this.showMo = true;
      this.$nextTick(() => {
        this.$refs.renyuanResults.init(this.rowId, "ry", "放大",'',updateFlag);
      });
    },
    renyuanChild(renyuanChild) {
      if(renyuanChild=='缩小'){
        this.mninnerVisible = true;
        this.$nextTick(() => {
          this.$refs.renyuanResults.init(this.rowId, "ry", "缩小",'人员',false);
        });
      }else{
        this.zongE=this.sum(renyuanChild.list)

        this.tableDataChild=renyuanChild.tableData
        this.tableColumnChild=renyuanChild.tableColumn
         console.log("WWW:"+JSON.stringify(this.tableData[0]))
        if(this.tableData.length==1&&this.tableData[0].jjxMc=='领导年终奖'){
          //this.$set(this.tableData[0],'jjJe',this.zongE)
          this.$set(this.tableData[0],'xsJe',this.zongE)
          this.changeJe(this.tableData[0])

        }
      }

    },
    //数组总和
    sum(arr) {
          return arr.reduce(function(prev, curr, idx, arr){
              return prev*1 + curr*1;
          });
      },
    //选择公式
    xuanGs(row) {
      this.$nextTick(() => {
        this.$refs.gongshi.init(row, "geren");
      });
    },
    //获取机构分组
    getjigou(jjDeptId) {
      //人员分组
      getRyfzbList(jjDeptId).then((res) => {
        console.log("人员分组:" + JSON.stringify(res));
        this.checkList = res.data.data;
        // for(var i in this.tableData){
        //     for(var j in this.checkList){

        //         if(this.checkList[j].id==this.tableData[i].id){
        //             this.tableData[i].ryfzMc=this.checkList[j].ryfzMc
        //             this.tableData[i].sl=this.checkList[j].sl
        //         }
        //     }
        // }
      });
    },
    // 定向分配
    directionalBtn() {
      this.dxfpinnerVisible = true;
      this.$nextTick((res) => {
        this.$refs.jiangjinfpjjfpdjbFpDxfp.init(this.row);
      });
    },
    //  修改
    addOrUpdateHandle() {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(this.rowId, "编辑");
      });
    },
    callback() {
      this.dxfpinnerVisible = false;
    },
    //合并单元格
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0 || columnIndex === 1) {
        const _row = this.spanArr[rowIndex] ? this.spanArr[rowIndex] : 0;
        const _col = _row > 0 ? 1 : 0;

        return {
          // [0,0] 表示这一行不显示， [2,1]表示行的合并数
          rowspan: _row,
          colspan: _col,
        };
      }
    },
    handleSuccess() {},
    //添加机构分配子集返回来
    refreshDataList(refreshDataList) {
      this.getjigou(this.jjDeptId);
    },
    fanhui() {
      this.$emit("jigouChild");
    },
    //调用模板
    diaoyong() {
      this.$nextTick(() => {
        var fpType = 0;
        this.$refs.mubanTableRef.init(this.jjfpId, fpType);
      });
    },
    //保存为模板
    keepMoBan() {
      this.$prompt("请输入模板名称", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(({ value }) => {
          if (value == "") {
            this.$message.closeAll()
            this.$message.warning("请填写模板名称!");
            return false;
          }
          var params = {
            jjfpId: this.rowId,
            value: value,
          };
          this.keepMuBan(params);
        })
        .catch(() => {
          this.$message.closeAll()
          this.$message({
            type: "info",
            message: "取消输入模板名称",
          });
        });
    },
    keepMuBan(data) {
      var params = {
        fpId: data.jjfpId,
        fpName: data.value,
        fpType: 0,
        fpSaveType: "b",
        fpData: this.tableData,
      };
      saveTemplate(params).then((res) => {
        if (res.data.code == 0) {
          this.$message.closeAll()
          this.$message({
            type: "success",
            message: "模板保存成功!",
          });
        }
      });
    },
    mubanTableChild(data) {
      var params = {
        row: data,
        id: this.rowId,
      };
      useTemplate(params).then((res) => {
        this.getData();
      });
    },
    downloadtemp() {
      downloadTemplate({ fpId: this.rowId }).then((response) => {
        this.$message.closeAll();
        this.$message.success("下载成功!");
        let url = window.URL.createObjectURL(new Blob([response.data]));
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", "人员分组模板.xlsx");
        document.body.appendChild(link);
        link.click();
      });
    },
    beforeFileUpload(file) {
      ////console.log(file);
      const cType = file.type;
      let isXls = false;

      // const isXls = file.type === 'xls/xlsx';
      if (
        cType === "application/vnd.ms-excel" ||
        cType ===
          "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      ) {
        isXls = true;
      }

      if (!isXls) {
        this.$message.closeAll()
        this.$message.error("导入文件只能是 Excel 格式!");
      }
      return isXls;
    },
    handleChange(file, fileList) {
      this.fileList = [];
      this.fileList.push(file);
    },
    //奖金结果导入
    handleUploadSuccessJj(response){
       this.$nextTick(() => {
          this.$refs.renyuanResults.init(this.rowId, "ry", "放大",'人员',false);
        });
    },
    handleUploadSuccess(response, file, fileList) {
      ////console.log('3232323')  show-overflow-tooltip
      this.showExist = true;

      if (response.code !== 0) {
        this.$message.closeAll()
        this.$message.error("上传出错：" + response.msg);
        return;
      }

      ////console.log(response.data.bucketName);//jxkh
      ////console.log(response.data.fileName);  //2021/07/27/09de9b8ed2e14996ba6b3a155d0a6884.xlsx
      //return false;
      this.bLoading = true;

      request({
        url:
          "/jiangjin/jiangjinfpjjfpdjb/allocationFile/" +
          response.data.bucketName +
          "/" +
          response.data.fileName +
          "/" +
          this.rowId,
        method: "get",
      })
        .then((res) => {
          // this.tableImpExcel = [];
          // this.tableImpExcel = res.data.data;
          // this.getDataList();
          this.bLoading = false;
          this.$message.closeAll();
          this.$message.success("导入成功!");
          this.getjigou(this.jjDeptId)
          this.getData()
          this.$refs.renyuanResults.daochu(this.rowId, "ry", "缩小",'',false);
        })
        .catch((error) => {
          this.bLoading = false;
          this.$message.closeAll();
          this.$message.error(error.message);
        });
    },
    changeVal(val){
      var obj ={}
      val.forEach(item=>{
        obj = this.checkList.find(ele=>{
          return ele.id == item
        })
      })

      if(obj.ryfzLx == 0){
        this.$message.closeAll();
        this.$message.warning("当前勾选分组是模板导入的数据");
      }
    }
  },
};
</script>

<style>
</style>
